﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WinFormsApp1
{
    internal class IniFileReader
    {
        private string filePath;

        public IniFileReader(string filePath)
        {
            this.filePath = filePath;
        }

        public string ReadValue(string section, string key)
        {
            string value = string.Empty;
            if (File.Exists(filePath))
            {
                var lines = File.ReadAllLines(filePath, Encoding.Default);
                foreach (var line in lines)
                {
                    var trimmedLine = line.Trim();
                    if (trimmedLine.StartsWith("[") && trimmedLine.EndsWith("]"))
                    {
                        var currentSection = trimmedLine.Substring(1, trimmedLine.Length - 2);
                        if (currentSection == section)
                        {
                            var keyValue = line.Split('=');
                            if (keyValue.Length == 2 && keyValue[0].Trim() == key)
                            {
                                value = keyValue[1].Trim();
                                break;
                            }
                        }
                    }
                }
            }
            return value;
        }
    }
}
